﻿<cfscript>
/** 
* ORM WorkLoad
* 
* @hint "Hibernate persistenter t_workload_fun. 工作量计算公式" 
* 
*/ 

component 
	displayname="public.service.orm.senate.WorkLoad" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="WorkLoad" 
	table="t_workload_fun"
	{
	
	property type="string" name="FunID" column="fun_id" fieldtype="id" generator="assigned" hint="工作量计算公式ID";

	property type="string" name="FunName" column="fun_name" hint="计算公式名称";
	property type="string" name="FunDescription" column="fun_describe" hint="计算公式说明";
	property type="string" name="FunMethod" column="fun_meta" hint="绑定计算方法名称";
	property type="string" name="FunArgs" column="fun_args" hint="计算系数列表";

	property name="TheoryCourses" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="theory_fun" cfc="CourseWorkLoad" hint="理论工作量计算方法课程";
	property name="PracticeCourses" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="practice_fun" cfc="CourseWorkLoad" hint="实践工作量计算方法课程";

	/**
	* @hint "自定义主键规则"
	* 
	* @FunMethod "绑定计算方法名称"
	*/
	public string function getNextID( required string FunMethod ) output=false {
		
		var nextID = arguments.FunMethod & numberFormat(1, "0_");
		var checkArray = ORMExecuteQuery("select FunID from WorkLoad 
											where FunID like :condition 
											order by FunID desc", { condition=arguments.FunMethod & "__" }, { maxResults=1 });

		/* 
			主键生成规则 CHAR(4)
			
			2位计算模版代码 2位流水号
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = arguments.FunMethod & numberFormat((right(checkArray[1], 2) + 1), "0_");
			
		}

		return nextID;

	}
		
}

</cfscript>